local nixun = fk.CreateSkill({
    name = "sj5__nixun",
    tags = {Skill.Compulsory,Skill.AttachedKingdom},
    attached_kingdom = {"jin"},
})

Fk:loadTranslationTable{
  ["sj5__nixun"] = "逆勋",
  [":sj5__nixun"] = "<b><font color='purple'>晋势力技</font></b>，<b>锁定技</b>，当你变更至此势力时，你令一名角色选择一项：1.回复1点体力；2.摸两张牌；3.视为使用一张<a href=':sanshe__enemy_at_the_gates'>【兵临城下】</a>。",

  ["$sj5__nixun1"] = "典午忽兮，月酉没兮。",
  ["$sj5__nixun2"] = "周慕孔子遗风，可与刘、扬同轨。",
  
  ["#sj5__nixun-hp"] = "回复1点体力",
  ["#sj5__nixun-draw"] = "摸两张牌",
  ["#sj5__nixun-blcx"] = "视为使用【兵临城下】",

  ["#sj5__nixun-ask"] = "逆勋：令一名角色进行<b>“逆勋”</b>选择",
}

nixun:addEffect(fk.AfterPropertyChange, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(nixun.name) and data.kingdom == "jin"
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local p = room:askToChoosePlayers(player,{
      targets = room:getAlivePlayers(),
      min_num = 1,
      max_num = 1,
      skill_name = nixun.name,
      prompt = "#sj5__nixun-ask",
      cancelable = false,
    })[1]
    local all = {"#sj5__nixun-hp","#sj5__nixun-draw","#sj5__nixun-blcx"}
    local ask = table.simpleClone(all)
    local blcx = Fk:cloneCard("sanshe__enemy_at_the_gates")
    if not p:isWounded() then
      table.removeOne(ask, "#sj5__nixun-hp")
    end
    if #blcx:getDefaultTarget(p) == 0 then
      table.removeOne(ask, "#sj5__nixun-blcx")
    end
    local choice = room:askToChoice(p,{
      choices = ask,
      skill_name = nixun.name,
      all_choices = all,
    })
    event:setCostData(self,{p = p, choice = choice})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cost = event:getCostData(self)
    local choice = cost.choice
    local p = cost.p
    if choice == "#sj5__nixun-hp" then
      room:recover{
        who = p,
        num = 1,
        recoverBy = player,
        skillName = nixun.name,
      }
    elseif choice == "#sj5__nixun-draw" then
      room:drawCards(p,2,nixun.name)
    else
      local use = room:askToUseVirtualCard(p,{
        name = "sanshe__enemy_at_the_gates",
        skill_name = nixun.name,
        cancelable = false,
        skip = true
      })
      if use then
        use.extra_data = {toArea = "top"}
        player.room:useCard(use)
      end
    end
  end,
})


return nixun